package com.analysis.common;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateUtil {
	
	public static java.sql.Date getSqlDate(String dateStr){
		java.sql.Date date = null;
		try {
			date = new java.sql.Date(DateFormat.getDateInstance().parse(dateStr).getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	public static java.sql.Date today(){
		return new java.sql.Date(new Date().getTime());
	}
	public static Date today(String pattern){
	    SimpleDateFormat format = new SimpleDateFormat(pattern);
	    Date date = new Date();
	    try {
            date = format.parse(format.format(new Date()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
	    return date;
	}
	public static String todayString() {
		return today().toString();
	}
	public static int getDateLen(java.sql.Date date1,java.sql.Date date2) {
		if(date1==null||date2==null) {
			return 0;
		}
		int days = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));
		return days<0?-days:days;
	}
	
}
